package com.vincent.kdp.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vincent.kdp.R;
import com.vincent.kdp.ui.bean.response.MemberSearchOutput;
import com.vincent.kdp.ui.bean.response.UncheckGoodsListOutput;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/6/13 0013.
 */
public class MemberSearchAdapter extends RecyclerView.Adapter<MemberSearchAdapter.ViewHolder> {

    private Context context;
    private OnItemClicker onItemClicker;
    private int itemCount = 0;
    private List<MemberSearchOutput.DataBean.ListBean> memberSearchOutputList = new ArrayList<>();

    public MemberSearchAdapter(Context context, OnItemClicker onItemClicker) {
        this.context = context;
        this.onItemClicker = onItemClicker;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        MemberSearchOutput.DataBean.ListBean c = memberSearchOutputList.get(position);
        holder.mBarCode.setText("商品条码："+c.getBarCode());
        holder.mMoney.setText("消费金额："+c.getMoney());
        holder.mConsumeNum.setText("消费单号："+c.getConsumeNum());
        holder.mName.setText("用户名称："+c.getName());

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_item_membersearch, parent, false);
        return new ViewHolder(view, onItemClicker);
    }

    public void refreshData(List<MemberSearchOutput.DataBean.ListBean> list) {
        memberSearchOutputList.clear();
        memberSearchOutputList = list;
        itemCount = memberSearchOutputList.size();
    }

    public void addData(List<MemberSearchOutput.DataBean.ListBean> list) {
        memberSearchOutputList.addAll(list);
        itemCount = memberSearchOutputList.size();
    }

    @Override
    public int getItemCount() {
        return itemCount;
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @Bind(R.id.money)
        TextView mMoney;
        @Bind(R.id.bar_code)
        TextView mBarCode;
        @Bind(R.id.consume_num)
        TextView mConsumeNum;
        @Bind(R.id.name)
        TextView mName;


        private OnItemClicker onCheckedItemClicker;

        public ViewHolder(View itemView, OnItemClicker onCheckedItemClicker) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
            this.onCheckedItemClicker = onCheckedItemClicker;
        }

        @Override
        public void onClick(View v) {
            onCheckedItemClicker.operate(v, getAdapterPosition(),mBarCode.getText().toString().trim());
            System.out.println(22);

        }
    }

    public interface OnItemClicker {
        void operate(View view, int position ,String barCode);
    }


}
